
////////////////////////////////////////////////////////////////////////////////
//
// JavaSum.java
//
// Copyright © (C) 2010
// 
// Emory Hughes Merryman, III
// emory.merryman@gmail.com
// 
// All Rights Reserved
// 
// This file is part of Interworks.
// 
// Interworks is free software: you can 
// redistribute it and/or modify it under 
// the terms of the GNU General Public 
// License as published by the Free 
// Software Foundation, either version 3 
// of the License, or (at your option) any 
// later version.
// 
// This program is distributed in the hope 
// that it will be useful, but WITHOUT 
// ANY WARRANTY; without even the 
// implied warranty of MERCHANTABILITY 
// or FITNESS FOR A PARTICULAR 
// PURPOSE.  See the GNU General Public 
// License for more details.
//
// You should have received a copy of the 
// GNU General Public License along with 
// this program.  If not, see 
// <http://www.gnu.org/licenses/>.
////////////////////////////////////////////////////////////////////////////////

package com . superiorglobalbusiness . researchr ;

import
    org . springframework . beans . factory . annotation .
    Autowired ;
import org . springframework . context . annotation . Scope ;

@ Scope ( "prototype" )
    final class JavaSum extends Sum
    {
	private int [ ] data_ ;

	@ Autowired
	    JavaSum ( final Integer numberOfTrials , final Integer sizeOfArray )
	{
	    super ( "Java" , numberOfTrials , sizeOfArray ) ;
	}

	@ Override
	    void setUp ( )
	{
	    int sizeOfArray = getSizeOfArray ( ) ;
	    data_ = new int [ sizeOfArray ] ;
	}

	@ Override
	    void tearDown ( )
	{
	    data_ = null ;
	}

	/**
	 * Performs a meaningless task - summing a bunch of zeroes.
	 * It is a benchmark.
	 **/
	@ Override
	    public Void call ( )
	{
	    for ( int i = 0 ; i < getNumberOfTrials ( ) ; i ++ )
		{
		    int sum = 0 ;
		    for ( int j = 0 ; j < data_ . length ; j ++ )
			{
			    sum += data_ [ j ] ;
			}
		    assert sum == 0 : "Bad Math" ;
		}
	    return ( null ) ;
	}
    }
